package pt.iscte.pcd.carrace;
import java.awt.Dimension;

import javax.swing.JFrame;

public class CarGame {
	public static final int NUM_CARS = 10;
	private static final int CAR_HEIGHT = 40;
	private JFrame frame = new JFrame("Car Race");
//	private Car[] cars = new Car[NUM];
	public CarGame() {
		Track track = new Track();
		createGUI(track);
		for (int i = 0; i < NUM_CARS; i++){
			System.out.println("Car " + i + " starting ");
			new Car(track, i, Track.NUM_STEPS).start();
//			cars[i] = new Car(track, i);
//			cars[i].start();
		}

	}

	private void createGUI(Track track) {
		
		frame.getContentPane().add(track);
//		JButton start = new JButton("Start");
//		frame.getContentPane().add(start);
//		start.
		//frame.setSize(500, 200);
		track.setPreferredSize(new Dimension(Track.LENGTH, Math.min(600, CAR_HEIGHT * NUM_CARS)));
		frame.pack();
		frame.setResizable(false);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
	}

	private void init() {
		frame.setVisible(true);
	}

	public static void main(String[] args) {
		new CarGame().init();
	}

}
